package com.soup.lab.basic.keyable;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.*;

public class SameKeyFreeExecutorServiceTestCase {

    private static final Logger logger = LoggerFactory.getLogger(SameKeyFreeExecutorServiceTestCase.class);

    @Test
    public void test() throws Exception {
        ExecutorService service = SameKeyFreeExecutorService.wrap(Executors.newFixedThreadPool(10));
        int i = 0;
        while(i++ < 100) {
            final int j = i;
            Future future = service.submit(Keyable.enchant((Callable) () -> {
                try {
                    TimeUnit.SECONDS.sleep(((j % 3) + 1) * 5);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                return j;
            }, () -> String.valueOf(j % 3)));
            TimeUnit.SECONDS.sleep(1);
            System.out.println(future);
        }
        TimeUnit.MINUTES.sleep(2);
    }


}
